using UnityEngine;

public class BloodOfMoonEvent : MonoBehaviour
{
    public static BloodOfMoonEvent instance;
    [Header("血月特效")]
    public GameObject bloodEffect;
    private void Awake()
    {
        instance=this;
    }
    private void Update()
    {
        if(GameManager.Instance.currLevelObj!=null)
        {
            CalculateBloodOfMoonTimer();
        }
    }
    //初始化
    public void Init()
    {
        if(GameManager.Instance.isBloodMoon)
        {
            //切换血月界面
            bloodEffect.SetActive(true);
            MsgMainEventIcon msg = new MsgMainEventIcon();
            msg.sprite=GameManager.Instance.eventIcon[1];
            EventManager.AddMsg(msg);
        }
    }
    //进入血月
    public void OpenBloodOfMoon()
    {
        GameManager.Instance.isBloodMoon=true;
        GameManager.Instance.bloodMoonTimer=90f;

        //让当前场景所有敌人关闭增益
        foreach (var i in SceneItemManager.instance.enemies)
        {
            i.GetComponent<Enemy>().BloodOfMoonInit();
        }

        //切换血月界面
        bloodEffect.SetActive(true);
        MsgMainEventIcon msg = new MsgMainEventIcon();
        msg.sprite=GameManager.Instance.eventIcon[1];
        EventManager.AddMsg(msg);

        TipSayManager.Instance.Say("<color=red> 血月 </color>降临");
    }
    //结束血月
    public void OverBloodOfMoon()
    {
        GameManager.Instance.isBloodMoon=false;
        //让当前场景所有敌人关闭增益
        foreach (var  i in SceneItemManager.instance.enemies)
        {
            i.GetComponent<Enemy>().ReduceModify();
        }
        //回到阳光界面
        bloodEffect.SetActive(false);
        MsgMainEventIcon msg = new MsgMainEventIcon();
        msg.sprite=GameManager.Instance.eventIcon[0];
        EventManager.AddMsg(msg);
    }
    //血月时间计时
    public void CalculateBloodOfMoonTimer()
    {
        if(GameManager.Instance.isBloodMoon)
        {
            GameManager.Instance.bloodMoonTimer-=Time.deltaTime;
            if(GameManager.Instance.bloodMoonTimer<=0)
            {
                GameManager.Instance.bloodMoonTimer=90;
                //血月结束
                OverBloodOfMoon();
            }
        }
    }
    //关闭特效
    public void CloseEffect()
    {
        bloodEffect.SetActive(false);
    }
    //打开特效
    public void OpenEffect()
    {
        bloodEffect.SetActive(true);
    }
}